package com.sxc.session;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/session01")
public class Session01 extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 获取Session对象
        HttpSession session = req.getSession();
        // 获取Session的会话标识符
        String id = session.getId();
        System.out.println(id);
        // 获取Session的创建时间
        System.out.println(session.getCreationTime());
        // 获取最后一次访问时间
        System.out.println(session.getLastAccessedTime());
        // 判断是否是新的Session对象
        System.out.println(session.isNew());
    }
}
